package com.entrogy.controller;


import com.entrogy.bean.SchoolBusTeacher;
import com.entrogy.service.SchoolBusTeacherService;
import com.entrogy.utils.ApiReturnUtil;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author 许红松
 * @date 2019/4/25 0025 下午 5:24
 * 校车跟车教师控制层
 */
@RestController
@RequestMapping(value = "/schoolBusTeacher")
@Api(description = "对学校校车跟车老师信息操作的相关接口")
public class SchoolBusTeacherController {

    @Autowired
    private SchoolBusTeacherService schoolBusTeacherService;//学校校车关联教师service接口

    /**
     *   校车跟车教师分页
     * @return List
     */
    @ApiOperation(value = "分页获取该Bus跟班老师信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "学校ID",name = "schoolCode",dataType = "int",paramType = "query",required = true),
            @ApiImplicitParam(value = "校车id",name = "busid",dataType = "String",paramType = "query",required = true),
            @ApiImplicitParam(name="page",value = "当前页数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(value = "每页条数",name = "total",dataType = "int",paramType = "query",required = true)
    })
    @RequestMapping(value = "/getSchoolBusTeacherList",method = RequestMethod.POST)
    public List<Map<String,Object>> getSchoolBusTeacherList(@RequestParam(value="page")int  page, @RequestParam(value="total")int  total, Integer schoolCode, String busid ){
        PageHelper.startPage(page,total);
        Map<String,Object> map=new HashMap<>();
        if ( busid!=null && !"".equals("busid")){
            map.put("busid",busid);
        }
        List<Map<String,Object>> list=schoolBusTeacherService.selectSchoolTList(map);
        return list;
    }

    /**
     *   新增校车跟车老师信息
     * @param schoolBusTeacher
     * @param schoolCode
     * @return
     */
    @ApiOperation(value = "新增校车跟车老师")
    @RequestMapping(value = "/insertSchoolBusTeacher",method = RequestMethod.POST)
    public Map<String,Object> insertSchoolBusTeacher(@ModelAttribute SchoolBusTeacher schoolBusTeacher, Integer schoolCode){
        if (schoolCode!=null && schoolCode>0){
            schoolBusTeacher.setSchool_code(schoolCode);
        }

        schoolBusTeacherService.insertSchoolBusTeacher(schoolBusTeacher);
        return ApiReturnUtil.success("新增成功","");

    }

    /**
     *   修改校车跟车老师信息
     * @return
     */
    @ApiOperation(value = "修改校车跟车老师")
    @RequestMapping(value = "/updateSchoolBusTeacher",method = RequestMethod.POST)
    public Map<String,Object> updateSchoolBusTeacher(@ModelAttribute SchoolBusTeacher schoolBusTeacher,Integer schoolCode,Integer id){
        if (schoolCode!=null && schoolCode>0){
            schoolBusTeacher.setSchool_code(schoolCode);
        }
        if (id!=null && id>0){
            schoolBusTeacher.setId(id);
        }
         schoolBusTeacherService.updateSchoolBusTeacher(schoolBusTeacher);

            return ApiReturnUtil.success("修改成功","");

    }

    /**
     *   删除校车跟车老师信息
     * @return
     */
    @ApiOperation(value = "删除校车跟车老师")
    @RequestMapping(value = "/deleteSchoolBusTeacher",method = RequestMethod.POST)
    public Map<String,Object> deleteSchoolBusTeacher(Integer schoolCode,String schoolbusTeacherId){
        if (schoolCode==null || schoolCode==0){
            return ApiReturnUtil.error("您无操作权限！");
        }
        schoolBusTeacherService.deleteSchoolBusTeacher(schoolbusTeacherId);
            return ApiReturnUtil.success("删除成功","");

    }



}
